import { GetModuleElementAuthority } from '@/services/auth';

export default {
  namespace: 'global',

  state: {
    currentUrl: '',
    elementAuth: {},
  },

  effects: {
    //获取当前页面Router
    *fetchUrl({ payload,callback }, { call, put }) {
      yield put({
        type: 'saveCurrentUrl',
        payload: payload,
      });
      
      callback("saveCurrentUrl");
    },

    //根据URL获取页面要素权限许可的角色
    *fetchAuthorityElements({ payload }, { call, put }) {
      // const url = yield select(state => state.currentUrl);
      const response = yield call(GetModuleElementAuthority, payload);

      yield put({
        type: 'saveAuth',
        payload: response,
      });
    },
  },

  reducers: {
    saveCurrentUrl(state, { payload }) {
      return {
        ...state,
        currentUrl: payload,
      };
    },
    saveAuth(state, { payload }) {
      return {
        ...state,
        elementAuth: payload,
      };
    },
  },
};
